namespace SimpleTPL;

public class SimpleTaskCompletionSource<TResult>
{
    private readonly SimpleTask<TResult> _task;
    private Func<TResult> _resultFunc;

    public SimpleTask<TResult> Task => _task;

    public SimpleTaskCompletionSource()
    {
        _task = new SimpleTask<TResult>(() => _resultFunc());
    }

    public void SetResult(TResult result)
    {
        _resultFunc = () => result;
        _task.SetResult(result);
    }

    public void SetException(Exception ex)
    {
        _task.SetException(ex);
    }
}